
package vn.aptech.project.model.dao;
import java.sql.SQLException;
import vn.aptech.project.model.dto.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

public class  tbladmin_DAO extends CommonDAO {
 public  tbladmin_DAO() throws ClassNotFoundException, SQLException, IOException {
 }


public Vector selectPWbyUse(String UseName) throws SQLException
{
String strSelect = "SELECT passwordad FROM FS_admin where account='"+UseName+"'";
return ExecSelect(strSelect);
}

public int insert(tbladmin_DTO  obj) throws SQLException
{
String strInsert = "INSERT INTO FS_admin VALUES (N'"+  obj.getaccount() +"'  ,N'"+ obj.getpasswordad() +"' )";
return  ExecNonQuery(strInsert);
}


public int update(tbladmin_DTO  obj) throws SQLException
{
String strUpdate = "UPDATE FS_admin SET account= N'"+ obj.getaccount()+"' ,"+"passwordad= N'"+obj.getpasswordad() +"' WHERE adminid="+ obj.getadminid() ;
return  ExecNonQuery(strUpdate);
}
public int getAdminidByAdminName(String Adminname) throws SQLException, FileNotFoundException, IOException
{
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
             } catch (ClassNotFoundException ex)
            {
            Logger.getLogger(tblorder_DAO.class.getName()).log(Level.SEVERE, null, ex);
            }
            String connectionString = "jdbc:sqlserver://localhost:1433;databaseName=FurnitureSystem;user=sa;password=1234567";
            Connection con = DriverManager.getConnection(connectionString);
            Statement statement = con.createStatement();
            String str = "Select adminid from FS_admin where account='"+Adminname+"'";
            ResultSet rs = statement.executeQuery(str);
            rs.next();
            Vector vt = new Vector();
            vt.add(rs.getObject("adminid"));
            int a =Integer.parseInt(String.valueOf(vt.get(0)));
            return a;

}

public int delete(int adminid) throws SQLException
{
String strDelete = "DELETE FROM FS_admin WHERE adminid="+adminid;
return  ExecNonQuery(strDelete);
}
}

